package com.zhoufy.spi.test;

import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.zhoufy.server.HelloService;

import java.util.ServiceLoader;
import java.util.Set;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-05-04.
 *
 * @author chouFy
 */
public class JavaSPIMain {


    public static void main(String[] args) {
//        final ServiceLoader<HelloService> helloServices = ServiceLoader.load(HelloService.class);
//
//        for (HelloService helloService : helloServices){
//            System.out.println(helloService.getClass().getName() + "：" + helloService.sayHello("aa"));
//        }

        ExtensionLoader<HelloService> extentionLoader = ExtensionLoader.getExtensionLoader(HelloService.class);

        Set<String> supportedExtensions = extentionLoader.getSupportedExtensions();
        for (String extension : supportedExtensions) {
            HelloService extension1 = extentionLoader.getExtension(extension);
            System.out.println(extension1.sayHello("我是"));
        }
    }
}
